package org.millioncall.yueyoga.admin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.ReservationDAO;
import org.millioncall.yueyoga.admin.model.Reservation;
import org.millioncall.yueyoga.admin.model.WeeklyUseTimes;

public class ReservationDAOImpl extends BaseDao implements ReservationDAO {

	@Override
	public void setProductWeeklyUseTimes(Map<String, Object> params) {
		this.getPagableSqlSessionTemplate().update(
				"updateMemberWeeklyUsetimes", params);
	}

	@Override
	public Reservation findReservationByScheduleId(Integer scheduleId) {
		return this.getPagableSqlSessionTemplate().selectOne(
				"findReservationByScheduleId", scheduleId);
	}

	@Override
	public int update(Reservation reservation) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", reservation.getId());
		map.put("memberId", reservation.getMemberId());
		map.put("isEnable", reservation.getIsEnable());
		map.put("lastModifyTime", reservation.getLastModifyTime());
		return this.getPagableSqlSessionTemplate().update("updateReservation",
				map);
	}

	@Override
	public List<Reservation> findReservationByMap(Map<String, Object> map) {
		return this.getPagableSqlSessionTemplate().selectList(
				"findReservationByMap", map);
	}

	@Override
	public int saveReservation(Reservation reservation) {
		return this.getPagableSqlSessionTemplate().insert("saveRservation",
				reservation);
	}

	@Override
	public List<Reservation> findReservationByCdts(Map<String, Object> map) {
		return this.getPagableSqlSessionTemplate().selectList(
				"findReservationByCdts", map);
	}

	@Override
	public boolean delReservationsByScheduleId(String scheduleId) {
		return this.getPagableSqlSessionTemplate().delete(
				"delReservationsByScheduleId", Integer.valueOf(scheduleId)) > 0;
	}

	@Override
	public boolean updateByReservation(Reservation reservation) {
		return this.getPagableSqlSessionTemplate().update(
				"updateByReservation", reservation) > 0;
	}

	@Override
	public Reservation findReservationById(Integer id) {
		return this.getPagableSqlSessionTemplate().selectOne(
				"findReservationById", id);
	}

	@Override
	public boolean cancelReservation(Integer reservateId) {
		return this.getPagableSqlSessionTemplate().update("cancelReservation",
				reservateId) > 0;
	}

	@Override
	public Integer findNextResvId(Integer scheduleId) {
		return this.getPagableSqlSessionTemplate().selectOne("findNextResvId",
				scheduleId);
	}

	@Override
	public int findResvCountByScheIdAndMemberId(String scheId, String memberId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("scheduleId", scheId);
		map.put("memberId", memberId);
		return this.getPagableSqlSessionTemplate().selectOne(
				"findResvCountByScheIdAndMemberId", map);
	}

	@Override
	public Reservation findResvScheduleInfoByScheIdAndMemberId(String scheId,
			String memberId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("scheduleId", scheId);
		map.put("memberId", memberId);
		return this.getPagableSqlSessionTemplate().selectOne(
				"findResvScheduleInfoByScheIdAndMemberId", map);
	}

	@Override
	public int cancelReserve(Map<String, Object> map) {
		return this.getPagableSqlSessionTemplate().update("cancelReverse", map);
	}

	@Override
	public WeeklyUseTimes getMemberWeeklyUseTimes(Integer memberId) {
		return this.getPagableSqlSessionTemplate().selectOne(
				"findMemberWeeklyUseTimes", memberId);
	}

}
